#!/bin/bash
### BEGIN INIT INFO
# Provides:          lance_auto_channel
# Required-Start:    $network $local_fs
# Required-Stop:     $network $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Start lance_nas
# Description: Start and Stop the lance_tool
### END INIT INFO
#
# Lance Tool
#
# chkconfig: 345 20 80
# description: Lance Tool
#
# /etc/rc.d/init.d/lance_*
# See how we were called.

BASE="lzx_auto_channel"

function time_stamp()
{
  date +%Y%m%d_%H%M%S
}

case "$1" in
    start)
        echo "`time_stamp`:Start `basename $0` ......"
        nohup /etc/init.d/$BASE "background" 1>/var/log/$BASE.log 2>&1 &
        exit 0
    ;;

    stop)
        echo "Stop `basename $0` ......"
        exit 0
    ;;

    restart)
        $0 stop
        $0 start
        exit 0
    ;;

    status)
        echo "Status of `basename $0`:"
        exit 0
    ;;

    background)
        echo "Wait 10 secs for network fully booted"
        sleep 10 # wait until fully booted
        /root/ssh -fq -U dahai dahai@10.0.0.2 \
          "bash ~/lancez/solutions/RAH/map_2222r2l_close.txt"
        /root/ssh -fq -U dahai dahai@10.0.0.2 \
          "bash ~/lancez/solutions/RAH/map_8088r2l_close.txt"
        /root/ssh -fq -U dahai dahai@10.0.0.2 \
          "bash ~/lancez/solutions/RAH/map_2222r2l_open.txt"
        /root/ssh -fq -U dahai dahai@10.0.0.2 \
          "bash ~/lancez/solutions/RAH/map_8088r2l_open.txt"
        exit 0
    ;;

    *)
        echo "Usage: /etc/init.d/`basename $0` {start|stop|restart|status}"
        exit 1
    ;;
esac


exit 0

